#include <sys_head.h>

pthread_mutex_t m1, m2;
int arr[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

void *abc(void *p)
{
    for (size_t i = 0; i < sizeof(arr) / sizeof(arr[0]); i++)
    {
        if (arr[i] % 2 == 0)
        {
            pthread_mutex_lock(&m2);
            printf("子线程%d\n",arr[i]);
            pthread_mutex_unlock(&m1);
        }
    }
}

int main(int argc, char const *argv[])
{
    pthread_t pt;
    pthread_create(&pt, NULL, abc, NULL);
    pthread_mutex_init(&m1, NULL);
    pthread_mutex_init(&m2, NULL);
    pthread_mutex_lock(&m2);
    for (size_t i = 0; i < sizeof(arr) / sizeof(arr[0]); i++)
    {
        if (arr[i] % 2 != 0)
        {
            pthread_mutex_lock(&m1);
            printf("主线程%d\n",arr[i]);
            pthread_mutex_unlock(&m2);
        }
    }
    void *ptest;
    pthread_join(pt, &ptest);
    return 0;
}
